package com.igeek.boot.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author fengqq
 * @Description MybatisPlus配置类
 * @Date 2024/8/22  14:08
 */
@Configuration
public class MybatisPlusConfig {

    //配置分页插件
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //创建分页插件
        PaginationInnerInterceptor innerInterceptor = new PaginationInnerInterceptor();
        //配置相关的属性
        //设置数据库的类型
        innerInterceptor.setDbType(DbType.MYSQL);
        //设置溢出总页数后是否进行处理  默认false不处理
        innerInterceptor.setOverflow(true);
        //设置单页分页条数限制 -1无限制
        innerInterceptor.setMaxLimit(-1L);
        //将分页插件 添加到 拦截器中
        interceptor.addInnerInterceptor(innerInterceptor);
        return interceptor;
    }

    //配置乐观锁插件
    @Bean
    public MybatisPlusInterceptor OptimisticLockerInnerInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
